<?php

namespace App\Store\Controllers\Wxapp;


use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Store\Models\Wxapp\WxappSwimg;
use App\Common\Services\Store\Common as StoreCommon;

class SwimgController extends Controller
{
    /**
     * 获取列表
     */
    public function getlist(Request $request)
    {
        $list = WxappSwimg::getList($request);
        return response()->json(['code' => '000', 'msg' => '获取成功', 'data' => $list]);
    }

    

    /**
     * 新增
     */
    public function dopostadd(Request $request)
    {
        $img_path = $request->img_path ?? '';

        if($img_path==''){
            return response()->json(['code' => '001', 'msg' => '电子章未上传']);
        }
        $cp_id = StoreCommon::getCurrentAccountCompanyId($request);
        $data = ['img_path'=>$img_path,'cp_id'=>$cp_id];
        $data['create_at'] = time();
        $data['update_at'] = time();
        WxappSwimg::create($data);
        return response()->json(['code' => '000', 'msg' => '新增成功']);
    }

    /**
     * 删除
     */
    public function dodel(Request $request)
    {
        $id = $request->id ?? 0;
        $cp_id = StoreCommon::getCurrentAccountCompanyId($request);
        $info = WxappSwimg::where([['id', $id],['cp_id',$cp_id]])->first();
        if (!$info) {
            return response()->json(['code' => '001', 'msg' => '参数错误']);
        }
        WxappSwimg::where([['id', $id]])->update(['is_del' => 2, 'del_at' => time()]);

        return response()->json(['code' => '000', 'msg' => '操作成功']);
    }
}